package io.cici.cc.mybatis.plus.core.injector;

import io.cici.cc.mybatis.plus.core.injector.methods.*;
import io.cici.cc.mybatis.plus.core.metadata.TableInfo;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

@Slf4j
public class DefaultSqlInjector extends AbstractSqlInjector {

    @Override
    public List<Method> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        Stream.Builder<Method> builder = Stream.<Method>builder().add(new Insert()).add(new Delete())
                .add(new Update()).add(new SelectCount()).add(new SelectMaps()).add(new SelectObjs())
                .add(new SelectList());
        if (tableInfo.havePK()) {
            builder.add(new DeleteById()).add(new DeleteBatchByIds()).add(new UpdateById()).add(new SelectById())
                    .add(new SelectBatchByIds());
        } else {
            log.warn(String.format("%s ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.",
                    tableInfo.getEntityType()));
        }
        return builder.build().collect(toList());
    }
}
